package com.ruifu.pls.service;

import com.ruifu.pls.entity.InvLotLocId;
import com.ruifu.pls.model.GLCallInputParam;
import com.ruifu.pls.model.InventoryForchWithEnter.GLinJson;
import com.ruifu.pls.repository.GInventoryRepository;
import com.ruifu.pls.utils.HttpUtils;
import com.ruifu.pls.utils.SighUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.List;

/**
 * ********************************************************
 * * @desc  ：
 * * @author  ${user}
 * * @date    ${date}
 * * @version v1.0
 * * ${tags}
 * *******************************************************
 */
@Service
public class InventoryService {
    @Autowired
    GInventoryRepository gInventoryRepository;
    public void postInventoryToGLin(){
        List<InvLotLocId> invLotLocIdList = gInventoryRepository.load();
       // List<GLinInventoryProducts> gLinInventoryProductsList = new ArrayList<>();
        GLinJson gLinJson = new GLinJson();
        for(int i = 0;i<invLotLocIdList.size();i++){
            gLinJson.products.add(invLotLocIdList.get(i).gLinInventoryProducts);
        }//转化
        GLCallInputParam glCallInputParam = new GLCallInputParam();
        glCallInputParam.setData(gLinJson);//传给的参数
        glCallInputParam.setMd5Sigh(SighUtil.getMD5(SighUtil.signParam(glCallInputParam)));
        glCallInputParam.setMethod("g2matrix.commodities.updateStock");//请求对方方法
        System.out.println(glCallInputParam.toString());
        try {
            System.out.println(HttpUtils.doPost("http://demo.api.g2link.cn:8081/", "router", glCallInputParam.toString()));//请求路径
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
